package datastructure.book.tujiesuanfa.queueastack.exercise.first;

import java.util.Stack;

/**
 * 使用2个栈实现一个队列
 */
public class CQueue {

    private final Stack<Integer> firStack = new Stack<>();
    private final Stack<Integer> secStack = new Stack<>();

    public CQueue() {

    }

    public void appendTail(int value) {
        firStack.push(value);
    }

    /**
     * 空，返回-1
     */
    public int deleteHead() {
        if (secStack.empty()) {
            if (firStack.empty()) {
                return -1;
            }
            while (!firStack.empty()) {
                Integer pop = firStack.pop();
                secStack.push(pop);
            }
        }
        return secStack.pop();
    }
}
